import 'package:flutter/cupertino.dart';


///
/// @Description 自定义GestureDetector,点击的时候增加键盘隐藏功能,不用每次都去复制隐藏键盘代码
/// @Author liuer
/// @CreateTime 2024年01月04日 10:50
class MyGestureDetector extends StatefulWidget {
  final Function() onTap;
  final HitTestBehavior behavior;
  final Widget? child;
  final bool isHiddenKeyboard;//是否隐藏键盘,默认点击按钮就隐藏键盘
  const MyGestureDetector({super.key, required this.onTap, required this.child,
    this.behavior = HitTestBehavior.opaque,this.isHiddenKeyboard = true});

  @override
  State<MyGestureDetector> createState() => _MyGestureDetectorState();
}

class _MyGestureDetectorState extends State<MyGestureDetector> {
  @override
  Widget build(BuildContext context) {
    return  GestureDetector(
      onTap: (){
        if(widget.isHiddenKeyboard){
          // 隐藏键盘
          FocusScope.of(context).requestFocus(FocusNode());
        }
        widget.onTap();
      },
      behavior:widget.behavior,
      child: widget.child,
    );
  }
}

